﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.DAL;


namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class TR_TrainingRequest : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        TR_TrainingRequestDAL tr_trainingdal = new TR_TrainingRequestDAL();
        TR_TrainingRequestInfo tr_traininginfo = new TR_TrainingRequestInfo();
                
        protected void Page_Load(object sender, EventArgs e)
        { 
            if (!IsPostBack)
            {
                Session["tmp_emp_seq"] = Request.QueryString["id"];
                //Session["UserID"] = "555";
                grdTRRequestList.DataSource = tr_trainingdal.GetFill();
                grdTRRequestList.DataBind();
                LoadStatus();
                
            }
            
        }

        protected void grdTRRequestList_ItemCommand(object o, GridCommandEventArgs e)
        {
            if (e.CommandName == "Sort" || e.CommandName == "Filter")
            {
                grdTRRequestList.DataSource = tr_trainingdal.GetFill();
                grdTRRequestList.DataBind();
            }          
            
        }
        

        protected void btnReceive_OnClick(object sender, EventArgs e)
        {
            for (int i = 0; i < grdTRRequestList.Items.Count; i++)
            {
                GridDataItem item = grdTRRequestList.Items[i];
                string comboStatus = cbStatus.SelectedValue;
                //CheckBox chk = (CheckBox)item["ClientSelectColumn"].Controls[0];                              
                //if (chk.Checked)
                if(grdTRRequestList.Items[i].Selected)
                {   
                    string strStatus = item["status_seq"].Text;
                    if (strStatus != comboStatus)
                    {
                        Int32 strRequestSeq = Convert.ToInt32(item["request_seq"].Text);
                        string UserID = ssMng.EmpSeq;

                        tr_traininginfo.request_seq = strRequestSeq;
                        tr_traininginfo.updated_by = UserID;
                        tr_traininginfo.updated_when = DateTime.Now;
                        tr_traininginfo.status_seq = Convert.ToInt32(cbStatus.SelectedValue);

                        tr_trainingdal.UpdateStatus(tr_traininginfo);
                    }
                }               
            }
            cbStatus.SelectedValue = "1";
            grdTRRequestList.DataSource = tr_trainingdal.GetFill();
            grdTRRequestList.DataBind(); 
        }
        public void LoadStatus()
        {
            DataSet ListDataCommand = tr_trainingdal.GetData("");
            DataTable table = ListDataCommand.Tables[0];
            cbStatus.DataSource = ListDataCommand.Tables[0];
            cbStatus.DataBind();
            
        }
        
        //protected void grdTRRequestList_ItemDataBound(object sender, GridItemEventArgs e)
        //{
        //    if (e.Item is GridDataItem)
        //    {
        //        GridDataItem item = (GridDataItem)e.Item;
        //        string strStatusSeq = item["status_seq"].Text;

        //        if (strStatusSeq != "2")
        //        {
        //            item["ClientSelectColumn"].Enabled = false;
        //        }
        //        else
        //        {
        //            item["ClientSelectColumn"].Enabled = true;
        //        }
        //    }
        //}             
    }
}
